package com.szzg10.webservice.chapter1;

import java.io.IOException;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class TimeClientHandler implements SOAPHandler<SOAPMessageContext> {

	@Override
	public boolean handleMessage(SOAPMessageContext ctx) {
		Boolean request_flag = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
		
		if(request_flag) {
			SOAPMessage message = ctx.getMessage();
			try {
				message.writeTo(System.out);
			} catch (SOAPException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		return true;
	}
	
	@Override
	public void close(MessageContext arg0) {}

	@Override
	public boolean handleFault(SOAPMessageContext arg0) {
		return true;
	}

	@Override
	public Set<QName> getHeaders() {
		return null;
	}

}
